package net.jmchilton.spring.collect;

import java.util.Iterator;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Adapts antiquated NodeList interface into an Iterable over
 * its nodes.
 * 
 * @author John Chilton
 * 
 */
class NodeListIterable implements Iterable<Node> {
  private final NodeList nodeList;
  
  NodeListIterable(final NodeList nodeList) {
    this.nodeList = nodeList;
  }
  
  public Iterator<Node> iterator() {
    return new Iterator<Node>() {
      private int i = 0;
      public boolean hasNext() {
        return i < nodeList.getLength();
      }
      public Node next() {
        return nodeList.item(i++);
      }
      public void remove() {
        throw new UnsupportedOperationException();
      }
    };
  }
}
